package com.toby.demo.quickfixj;

import java.util.Date;
import java.util.Scanner;

import com.toby.demo.quickfixj.sender.FIXSender;

import quickfix.Application;
import quickfix.ConfigError;
import quickfix.DefaultMessageFactory;
import quickfix.FileStoreFactory;
import quickfix.LogFactory;
import quickfix.MessageFactory;
import quickfix.MessageStoreFactory;
import quickfix.ScreenLogFactory;
import quickfix.Session;
import quickfix.SessionID;
import quickfix.SessionNotFound;
import quickfix.SessionSettings;
import quickfix.SocketInitiator;
import quickfix.field.ClOrdID;
import quickfix.field.OrdType;
import quickfix.field.OrderQty;
import quickfix.field.Price;
import quickfix.field.Side;
import quickfix.field.Symbol;
import quickfix.field.TransactTime;
import quickfix.fix44.NewOrderSingle;

public class SenderApp {

	public static void main(String[] args) throws ConfigError,
			InterruptedException, SessionNotFound {
		SessionSettings settings = new SessionSettings("sender.cfg");
		Application application = new FIXSender();
		MessageStoreFactory messageStoreFactory = new FileStoreFactory(settings);
		LogFactory logFactory = new ScreenLogFactory(settings);
		MessageFactory messageFactory = new DefaultMessageFactory();
		SocketInitiator initiator = new SocketInitiator(application,
				messageStoreFactory, settings, logFactory, messageFactory);
		initiator.start();

		SessionID sessionID = new SessionID("FIX.4.4", "CLIENT1", "FixServer_Tobby");
		NewOrderSingle order = new NewOrderSingle(new ClOrdID("DLF_T"), new Side(
				Side.BUY), new TransactTime(new Date()), new OrdType(
				OrdType.LIMIT));
		order.set(new OrderQty(4598.00));
		order.set(new Price(25.4888));
		order.set(new Symbol("BHP"));
		Session.sendToTarget(order, sessionID);
		// Thread.sleep(60000);
		Scanner scanner = new Scanner(System.in);
		scanner.nextLine();
		scanner.close();
	}

}
